home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / CXDemo.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  7KB  |  238 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/CXDemo.c,v 41.11 2000/05/09 20:33:19 mlemos Exp $
  3.  *
  4.  * CXDemo.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: CXDemo.c,v $
  12.  * Revision 41.11  2000/05/09 20:33:19  mlemos
  13.  * Bumped to revision 41.11
  14.  *
  15.  * Revision 1.2  2000/05/09 19:58:40  mlemos
  16.  * Merged with the branch Manuel_Lemos_fixes.
  17.  *
  18.  * Revision 1.1.2.1  1998/02/28 17:45:09  mlemos
  19.  * Ian sources
  20.  *
  21.  *
  22.  */
  23.  
  24. /* Execute me to compile with DICE V3.0.
  25. dcc CXDemo.c -proto -mi -ms -mRR -lbgui
  26. quit
  27. */
  28.  
  29. #include "DemoCode.h"
  30.  
  31. /*
  32. **      Key ID.
  33. **/
  34. #define CX_F1_PRESSED           1L
  35.  
  36. /*
  37. **      Gadget ID's.
  38. **/
  39. #define ID_HIDE                 1L
  40. #define ID_QUIT                 2L
  41.  
  42. /*
  43. **      Information text.
  44. **/
  45. UBYTE *InfoTxt = ISEQ_C ISEQ_B ISEQ_HIGHLIGHT
  46.                  "\33sCxDemo\n\n" ISEQ_TEXT ISEQ_N
  47.                  "This is a small \"do-nothing\" example of how\n"
  48.                  "to use the BGUI commodity class.\n"
  49.                  "In this example F1 is the Hotkey used to\n"
  50.                  "signal the broker to open the window.";
  51.  
  52. VOID StartDemo( void )
  53. {
  54.     Object    *CM_Broker, *WN_Window, *GA_Hide, *GA_Quit;
  55.     ULONG        signal = 0L, winsig = 0L, sigrec, type, id, rc;
  56.     BOOL        running = TRUE;
  57.  
  58.     /*
  59.     **      Setup a commodity object.
  60.     **/
  61.     CM_Broker = CommodityObject,
  62.         COMM_Name,              "CxDemo",
  63.         COMM_Title,             "Simple BGUI broker.",
  64.         COMM_Description,       "Does not do anything useful.",
  65.         COMM_ShowHide,          TRUE,
  66.     EndObject;
  67.  
  68.     /*
  69.     **      Object OK?
  70.     **/
  71.     if ( CM_Broker )
  72.     {
  73.         /*
  74.         **      Create a small window.
  75.         **/
  76.         WN_Window = WindowObject,
  77.             WINDOW_Title,           "CxDemo",
  78.             WINDOW_RMBTrap,         TRUE,
  79.             WINDOW_SizeGadget,      FALSE,  /* No use in this window. */
  80.             WINDOW_AutoAspect,      TRUE,
  81.             WINDOW_AutoKeyLabel,        TRUE,
  82.             WINDOW_MasterGroup,
  83.                 VGroupObject, HOffset(6), VOffset(6), Spacing(6), GROUP_BackFill, FILL_RASTER,
  84.                     StartMember,
  85.                         InfoObject, ButtonFrame,
  86.                             FRM_Flags,                FRF_RECESSED,
  87.                             INFO_TextFormat,        InfoTxt,
  88.                             INFO_FixTextWidth,    TRUE,
  89.                             INFO_MinLines,            6,
  90.                         EndObject,
  91.                     EndMember,
  92.                     StartMember,
  93.                         HGroupObject,
  94.                             StartMember, GA_Hide = FuzzButton( "_Hide", ID_HIDE ), EndMember,
  95.                             VarSpace(DEFAULT_WEIGHT),
  96.                             StartMember, GA_Quit = FuzzButton( "_Quit", ID_QUIT ), EndMember,
  97.                         EndObject, FixMinHeight,
  98.                     EndMember,
  99.                 EndObject,
  100.             EndObject;
  101.  
  102.         /*
  103.         **      Window OK?
  104.         **/
  105.         if ( WN_Window )
  106.         {
  107.             /*
  108.             **      Add F1 as hotkey.
  109.             **/
  110.             if ( AddHotkey( CM_Broker, "f1", CX_F1_PRESSED, 0L ))
  111.             {
  112.                 /*
  113.                 **        Obtain broker signal mask.
  114.                 **/
  115.                 GetAttr( COMM_SigMask, CM_Broker, &signal );
  116.                 /*
  117.                 **      Activate the broker.
  118.                 **/
  119.                 EnableBroker( CM_Broker );
  120.                 /*
  121.                 **      Open up the window.
  122.                 **/
  123.                 if ( WindowOpen( WN_Window ))
  124.                 {
  125.                     /*
  126.                     **      Obtain window sigmask.
  127.                     **/
  128.                     GetAttr( WINDOW_SigMask, WN_Window, &winsig );
  129.                     /*
  130.                     **      Wait for messages.
  131.                     **/
  132.                     do {
  133.                         sigrec = Wait( signal | winsig | SIGBREAKF_CTRL_C );
  134.                         /*
  135.                         **      Broker signal?
  136.                         **/
  137.                         if ( sigrec & signal )
  138.                         {
  139.                             /*
  140.                             **      Obtain the messages from the broker.
  141.                             **/
  142.                             while ( MsgInfo( CM_Broker, &type, &id, NULL ) != CMMI_NOMORE )
  143.                             {
  144.                         /*
  145.                         **      Evaluate message.
  146.                         **/
  147.                         switch ( type ) {
  148.  
  149.                            case    CXM_IEVENT:
  150.                               switch ( id ) {
  151.  
  152.                                  case    CX_F1_PRESSED:
  153.                                     goto openUp;
  154.                               }
  155.                               break;
  156.  
  157.                            case    CXM_COMMAND:
  158.                               switch ( id ) {
  159.  
  160.                                  case    CXCMD_KILL:
  161.                                     Tell( "bye bye\n" );
  162.                                     running = FALSE;
  163.                                     break;
  164.  
  165.                                  case    CXCMD_DISABLE:
  166.                                     Tell( "broker disabled\n" );
  167.                                     DisableBroker( CM_Broker );
  168.                                     break;
  169.  
  170.                                  case    CXCMD_ENABLE:
  171.                                     Tell( "broker enabled\n" );
  172.                                     EnableBroker( CM_Broker );
  173.                                     break;
  174.  
  175.                                  case    CXCMD_UNIQUE:
  176.                                  case    CXCMD_APPEAR:
  177.                                     openUp:
  178.                                     if ( WindowOpen( WN_Window ))
  179.                                        GetAttr( WINDOW_SigMask, WN_Window, &winsig );
  180.                                     break;
  181.  
  182.                                  case    CXCMD_DISAPPEAR:
  183.                                     WindowClose( WN_Window );
  184.                                     winsig = 0L;
  185.                                     break;
  186.                               }
  187.                               break;
  188.                         }
  189.                      }
  190.                   }
  191.  
  192.                   /*
  193.                   **      Window signal?
  194.                   **/
  195.                   if ( sigrec & winsig ) {
  196.                      while ( WN_Window && (( rc = HandleEvent( WN_Window )) != WMHI_NOMORE )) {
  197.                         switch ( rc ) {
  198.  
  199.                            case ID_HIDE:
  200.                            case WMHI_CLOSEWINDOW:
  201.                               /*
  202.                               **      Hide the window.
  203.                               **/
  204.                               WindowClose( WN_Window );
  205.                               winsig = 0L;
  206.                               break;
  207.  
  208.                            case ID_QUIT:
  209.                               /*
  210.                               **      The end.
  211.                               **/
  212.                               Tell( "bye bye\n" );
  213.                               running = FALSE;
  214.                               break;
  215.                         }
  216.                      }
  217.                   }
  218.  
  219.                   /*
  220.                   **      CTRL+C?
  221.                   **/
  222.                   if ( sigrec & SIGBREAKF_CTRL_C ) {
  223.                      Tell( "bye bye\n" );
  224.                      running = FALSE;
  225.                   }
  226.                } while ( running );
  227.             } else
  228.                Tell( "unable to open the window\n" );
  229.          } else
  230.             Tell( "unable to add the hotkey\n" );
  231.          DisposeObject( WN_Window );
  232.       } else
  233.          Tell( "unable to create a window object\n" );
  234.       DisposeObject( CM_Broker );
  235.    } else
  236.       Tell( "unable to create a commodity object\n" );
  237. }
  238.